﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TjZheng.Framework;
using TjZheng.JiaLi.Process;
using TjZheng.Windows.Forms;

namespace TjZheng.JiaLi.Activate.Winform
{
    public partial class RegisterForm : TjZhengForm
    {
        public RegisterForm()
        {
            InitializeComponent();
        }

        private void Btn_GetInput_Click(object sender, EventArgs e)
        {
            if (Txt_Input.Text.IsNull())
            {
                base.ShowMessage("请填写机器码信息");
                return;
            }
            try
            {
                TicketInfo objTicketInfo = Txt_Input.Text.DecryptDES("jqmhtjtz").JsonDeserialize<TicketInfo>();
                Txt_Version.Text = objTicketInfo.Version;
                Txt_BindAccount.Text = objTicketInfo.BindAccount;
                Txt_CPU.Text = objTicketInfo.CpuIdentity;
                //Txt_HardDisk.Text = objTicketInfo.MachineInfo.HardDiskIdentity;
                //Txt_BaseBoard.Text = objTicketInfo.MachineInfo.BaseBoardIdentity;
                //Txt_MacAddress.Text = objTicketInfo.MachineInfo.MacAddress;
                Dtp_CreateTime.Value = objTicketInfo.CreateTime.AddHours(8);
                Dtp_ExpireTime.Value = objTicketInfo.ExpireTime.HasValue ? objTicketInfo.ExpireTime.Value.AddHours(8) : Dtp_ExpireTime.MinDate;
            }
            catch (Exception objException)
            {
                base.ShowMessage("获取机器码信息发生异常，异常消息：" + objException.Message);
            }
        }

        private void Btn_CreateValid_Click(object sender, EventArgs e)
        {
            if (Dtp_ExpireTime.Value == Dtp_ExpireTime.MinDate)
            {
                base.ShowMessage("请选择过期时间");
                return;
            }
            if (Dtp_ExpireTime.Value <= Dtp_CreateTime.Value)
            {
                base.ShowMessage("过期时间应该比生成时间晚");
                return;
            }
            try
            {
                TicketInfo objTicketInfo = Txt_Input.Text.DecryptDES("jqmhtjtz").JsonDeserialize<TicketInfo>();
                objTicketInfo.ExpireTime = Convert.ToDateTime(Dtp_ExpireTime.Text);
                Txt_Valid.Text = objTicketInfo.JsonSerialize().EncryptDES("jqmhtjtz");
            }
            catch (Exception objException)
            {
                base.ShowMessage("生成激活码信息发生异常，异常消息：" + objException.Message);
            }
        }
    }
}
